package com.ailanyin.modules.search.controller;

import com.ailanyin.common.base.domain.BaseQuery;
import com.ailanyin.common.base.result.AjaxResult;
import com.ailanyin.modules.search.domain.TestEs;
import com.ailanyin.modules.search.service.TestEsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ailanyin
 * @version 1.0
 * @since 2022/9/29 0029 上午 10:04
 */
@RestController
@RequestMapping("/es")
@Api(tags = "EasyEs测试")
public class TestEsController {

    @Autowired
    private TestEsService testEsService;

    @PostMapping("/importData")
    @ApiOperation(value = "导入数据到Es")
    public AjaxResult importData() {
        testEsService.importDataToEs();
        return AjaxResult.success();
    }


    @GetMapping
    public AjaxResult getInfo(@RequestParam("id") Long id) {
        return AjaxResult.success(testEsService.selectById(id));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody TestEs testEs) {
        return AjaxResult.toAjax(testEsService.update(testEs));
    }

    @DeleteMapping
    public AjaxResult remove(@RequestBody BaseQuery<Long> query) {
        return AjaxResult.toAjax(testEsService.deleteByIds(query.getIds()));
    }

    @GetMapping("/search")
    public AjaxResult search(@RequestParam("param") String param) {
        return AjaxResult.success(testEsService.search(param));
    }
}
